<meta charset="utf-8">
(#) Missing Default

!!! ERROR: Missing Default
   This is an error, and is also enforced at build time when
   supported by the build system. For Android this means it will
   run during release builds.

Id
:   `MissingDefaultResource`
Summary
:   Missing Default
Severity
:   Fatal
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   3.2.0 (September 2018)
Affects
:   Binary resource files, resource files and resource folders
Editing
:   This check runs on the fly in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.kt)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt)

If a resource is only defined in folders with qualifiers like `-land` or
`-en`, and there is no default declaration in the base folder (`layout`
or `values` etc), then the app will crash if that resource is accessed
on a device where the device is in a configuration missing the given
qualifier.

As a special case, drawables do not have to be specified in the base
folder; if there is a match in a density folder (such as
`drawable-mdpi`) that image will be used and scaled. Note however that
if you  only specify a drawable in a folder like `drawable-en-hdpi`, the
app will crash in non-English locales.

There may be scenarios where you have a resource, such as a `-fr`
drawable, which is only referenced from some other resource with the
same qualifiers (such as a `-fr` style), which itself has safe
fallbacks. However, this still makes it possible for somebody to
accidentally reference the drawable and crash, so it is safer to create
a default fallback in the base folder. Alternatively, you can suppress
the issue by adding `tools:ignore="MissingDefaultResource"` on the
element.

(This scenario frequently happens with string translations, where you
might delete code and the corresponding resources, but forget to delete
a translation. There is a dedicated issue id for that scenario, with the
id `ExtraTranslation`.)

!!! Tip
   This lint check has an associated quickfix available in the IDE.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/values-land/dimen.xml:4:Error: The dimen "extra_dimen1" in
values-land has no declaration in the base values folder; this can lead
to crashes when the resource is queried in a configuration that does not
match this qualifier [MissingDefaultResource]
    &lt;dimen name="extra_dimen1"&gt;1pt&lt;/dimen&gt; &lt;!-- error --&gt;
           -------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant source files:

`res/values/dimen.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;
    &lt;dimen name="ok_dimen"&gt;base&lt;/dimen&gt; &lt;!-- ok --&gt;
    &lt;style name="ok_style"&gt;&lt;/style&gt; &lt;!-- ok --&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values-land/dimen.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;
    &lt;dimen name="ok_dimen"&gt;1pt&lt;/dimen&gt; &lt;!-- ok --&gt;
    &lt;style name="ok_style"&gt;&lt;/style&gt; &lt;!-- ok --&gt;
    &lt;dimen name="extra_dimen1"&gt;1pt&lt;/dimen&gt; &lt;!-- error --&gt;
    &lt;style name="extra_style1"&gt;&lt;/style&gt; &lt;!-- ok --&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values-v21/dimen.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;
    &lt;!-- We allow common scenario of having dedicated
         resources for API levels, often used for theming --&gt;
    &lt;dimen name="ok_extra_dimen"&gt;1pt&lt;/dimen&gt; &lt;!-- ok --&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values-land-v21/dimen.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;
    &lt;dimen name="ok_extra_dimen"&gt;2pt&lt;/dimen&gt; &lt;!-- ok --&gt;
    &lt;dimen name="extra_dimen2"&gt;1pt&lt;/dimen&gt; &lt;!-- error --&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/drawable-mdpi/ok_drawable.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;
    &lt;drawable name="color_drawable"&gt;#ffffffff&lt;/drawable&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/color/ok_color.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;color xmlns:android="http://schemas.android.com/apk/res/android" android:color="#ff0000" /&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/color-port/extra_color.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;color xmlns:android="http://schemas.android.com/apk/res/android" android:color="#ff0000" /&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/layout-land/extra_layout.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;merge/&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.kt)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `TranslationDetector.testExtraResourcesOfOtherTypes`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Adding the suppression attribute
  `tools:ignore="MissingDefaultResource"` on the problematic XML
  element (or one of its enclosing elements). You may also need to add
  the following namespace declaration on the root element in the XML
  file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="MissingDefaultResource" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'MissingDefaultResource'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore MissingDefaultResource ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>